package logic

import (
	"context"
	"customer/customerrpc/customerrpc"
	"customer/customerrpc/internal/svc"
	"customer/customerrpc/models"
	"fmt"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddLogic {
	return &AddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 新增
func (l *AddLogic) Add(in *customerrpc.AddRequest) (*customerrpc.AddResponse, error) {
	// todo: add your logic here and delete this line
	customer := models.Customer{
		Name:    in.Name,
		Static:  in.Static,
		Address: in.Address,
	}
	if in.Name == "" || in.Static == "" || in.Address == "" {
		return nil, fmt.Errorf("厂库不能为空")

	}
	models.DB.Create(&customer)
	return &customerrpc.AddResponse{
		Id: int64(customer.ID),
	}, nil
}
